from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class Base():
    def __init__(self):
        cap={
          "platformName": "Android",
          "appium:deviceName": "emulator-5554",
          "appium:automationName": "uiautomator2",
          "appium:appPackage": "cn.xuexi.android",
          "appium:appActivity": "com.alibaba.android.rimet.biz.home.activity.HomeActivity",
          "appium:noReset": True
        }
        #远程连接
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        #隐式等待40s
        self.driver.implicitly_wait(40)

    # 找元素方法
    def find_ele(self, loc):
        ele = self.driver.find_element(*loc)
        return ele

    # 显示等待方法
    def find_ele_wait(self, loc):
        ele = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(loc))
        return ele

    # 轻敲
    def qingqiao(self, x, y):
        ele = self.driver.tap([(x, y)], 200)
        return ele

    # 滑动
    def huadong(self, a, b, c, d):
        ele = self.driver.swipe(a, b, c, d, 100)
        return ele

    # 截屏
    def jieping(self, a):
        ele = self.driver.save_screenshot(a)
        return ele